﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace One.Framework.Util
{
    /// <summary>
    /// 랜덤
    /// </summary>
    public class RandomHelper
    {
        /// <summary>
        /// 랜덤 문자
        /// </summary>
        /// <param name="seed">시드값</param>
        /// <param name="size">문자길이</param>
        /// <param name="lowerCase">true이면 소문자로 생성</param>
        /// <returns>랜덤 문자 반환</returns>
        public static string RandomString(int seed, int size, bool lowerCase)
        {
            Random random = new Random(seed);

            // StringBuilder is faster than using strings (+=)
            StringBuilder RandStr = new StringBuilder(size);

            // Ascii start position (65 = A / 97 = a)
            int Start = (lowerCase) ? 97 : 65;

            // Add random chars
            for (int i = 0; i < size; i++)
                RandStr.Append((char)(26 * random.NextDouble() + Start));

            return RandStr.ToString();
        }

        /// <summary>
        /// 랜덤 숫자
        /// </summary>
        /// <param name="seed">시드값</param>
        /// <param name="Minimal">최소값</param>
        /// <param name="Maximal">최대값</param>
        /// <returns>Random number</returns>
        public static int RandomNumber(int seed, int Minimal, int Maximal)
        {
            Random random = new Random(seed);
            return random.Next(Minimal, Maximal);
        }

        /// <summary>
        /// 랜덤 bool
        /// </summary>
        /// <param name="seed">시드값</param>
        /// <returns>랜덤 boolean 반환</returns>
        public static bool RandomBool(int seed)
        {
            Random random = new Random(seed);
            return (random.NextDouble() > 0.5);
        }

        /// <summary>
        /// 랜덤 RGB Color
        /// </summary>
        /// <param name="seed">시드값</param>
        /// <returns></returns>
        public static System.Drawing.Color RandomColor(int seed)
        {
            Random random = new Random(seed);
            int red = random.Next(255);
            int green = random.Next(255);
            int blue = random.Next(255);

            return System.Drawing.Color.FromArgb(red, green, blue);
        }
    }
}
